using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for bzOnline
/// </summary>
public class bzOnline
{
    dbConnection _DB = null;
    public bzOnline()
    {
        _DB = new dbConnection();
    }
    public int delete(string IP)
    {
        SqlParameter p = new SqlParameter("@IP", IP);
        return _DB.updateData("bzOnline_delete",p);
    }
    public int insert(string IP)
    {
        SqlParameter p = new SqlParameter("@IP", IP);
        return _DB.updateData("bzOnline_insert",p);
    }
    
    public string getOnline(string IP)
    {
        DataTable dt = _DB.getDataTable("bzOnline_getData");
        foreach (DataRow dr in dt.Rows)
        {
            TimeSpan t = DateTime.Now - Convert.ToDateTime(dr["LoginTime"]);
            if (t.TotalSeconds > 5 * 60)
            {
                this.delete(dr["IP"].ToString());
            }
        }
        this.insert(IP);
        dt = _DB.getDataTable("bzOnline_getOnline");
        try
        {
            long i = Convert.ToInt64(dt.Rows[0][0]);
            return i.ToString();
        }
        catch { }
        return "1";
    }
}
